<?php

class ADespachoExtra {

    public function __construct(){
	}
	public function generarCheckList(EFacade & $facade)
	{
		$docDD = & $facade->getDocumentRoot();
	
		//$OMCh = & $docSLU->ordenMCheckListPrincipal;
		$usuario=NULL;

		$ezpdo_= getManager();
		$x = 0;
		foreach($docDD->instanciaEquipos as $bus){
			
			$checkList = $facade->session->create('DCheckListOperaciones');	
				$checkList->cantidadInicial = 0;
				$checkList->cantidadFinal = 0;
//				$checkList->averia = '234';
//				$checkList->descripcionAveria = 'sdfg';
				$checkList->despachoExtra =$docDD;
				$checkList->equipo = $bus;
			$checkList->epSetDirty(TRUE);
//			if($checkList->despacho = $docDD)
//				echo '<hr>- ajo  ';
//			$checkList->equipo = $bus;
			$checkList->areaTrabajo = $ezpdo_->get('MAreaTrabajo',3);
			$empleado = $docDD->empleados;
//			echo '<hr>- trbajo  ',$checkList;
			foreach($docDD->empleados as $emple)
			
			for($i = 0;$i<2;$i++){
				$checkList->empleados[] = $empleado[$x];
			
				$x++;
				
				//echo '<hr>- trbajo  ',$checkList;
			}
			
			$role=NULL;
			$newEfacade =& EFacade :: initWorkflow($facade->session, $checkList, & $role);
			$transSet = & EFacade :: getCurrentTransSetAuto($newEfacade->getWorkflow(),3);//tipo process
			$trans = $transSet->getTransByName('t1');
			$usuario=NULL;
			
			$newEfacade->fireTrans($trans, $usuario, "Crear",TRUE);
	
			$checkList->epSetDirty(TRUE);// marcar el documento para que sea salvado los cambios
			$newEfacade->saveWorkflow();
	
			$checkList->commit();//echo "<br><br> es:1 ";
			$checkList->numero = $checkList->getDocumentNumber();
			$checkList->commit();
		
			
		}
		unset($newEfacade);
		$docDD->epSetDirty(TRUE);
		
		$workflows = & $facade->getWorkflow();
		$workflows->epSetDirty(TRUE);

		$transSetOSL = & EFacade :: getCurrentTransSetAuto($workflows, /* MTrans :: $TYPE_AUTO_AGENT */ 2);
		$listaWT= &$workflows->getWorkTransList();

		$transOSL = $transSetOSL->getTransByName('t2');
		$facade->fireTrans($transOSL,$usuario,'Creacion de Ordenes', TRUE);	
		$facade->saveWorkflow();
		$docDD->commit();
		
	}

	

}
?>